{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <div class="demoTable">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
        </div>
        <button class="layui-btn" id="search" data-type="reload">{:lang('search')}</button>
        <div style="clear: both;"></div>
    </div>
    <script type="text/html" id="action">
        <a class="layui-btn layui-btn layui-btn-xs" lay-event="add">关联</a>
    </script>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="title">
   {{d.title}}{{# if(d.pic){ }}<img src="/static/admin/images/image.gif" onmouseover="layer.tips('<img src={{d.pic}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">{{# } }}
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var course_id = {$course_id};
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("goodsList")}',
            method: 'post',
            where: {course_id: course_id},
            page:true,
            cols: [[
                // {checkbox: true, fixed: true},
                {field: 'id', title: '{:lang("id")}', width: 80, fixed: true},
                {field: 'name', title: '商品名称', width: 220},
                {field: 'desc', title: '描述', width: 250},
                {width: 180,title:'操作', align: 'center', toolbar: '#action'}
            ]],
            limit:10
        });
       
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            if ($.trim(key) === '') {
                layer.msg('{:lang("pleaseEnter")}关键字！', {icon: 0});
                return;
            }
            tableIn.reload({ page: {page: 1}, where: {key: key}});
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'add'){
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('add')}",{goods_id:data.id, course_id:course_id},function(res){
                    layer.close(loading);
                    if(res.code===1){
                        layer.msg(res.msg,{time:2000,icon:1});
                        parent.location.reload();
                    }else{
                        layer.msg(res.msg,{time:2000,icon:2});
                    }
                });
            }
        });
        $('body').on('blur','.list_order',function() {
            var id = $(this).attr('data-id');
            var sort = $(this).val();
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post('{:url("order")}',{id:id,sort:sort},function(res){
                layer.close(loading);
                if(res.code === 1){
                    layer.msg(res.msg, {time: 1000, icon: 1});
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        });
        $('#addGoods').click(function(){
            
        })
    })
</script>